#!/bin/sh
#set -x
###########################################################################################
#author  :      dengxh
#date:      2009/03/17
###########################################################################################

VERSION="V1.0"
input_param=$*

param_num=$#
Date=`date +%Y%m%d%T`

while true
do 
	if [ "$1"x = "-f"x ]
	then
		shift 1
		origin_filename=$1
	fi
	shift 1
	if [ $# -eq 0 ]
	then
		break
	fi
done


uniq_file=`echo ${origin_filename}|sed "s/\.dat/_uniq.dat/g"`
#echo 'uniq_file ' $uniq_file
#echo 'input_param ' $input_param
#echo 'origin_filename ' $origin_filename


#echo $new_param
if [  -f $uniq_file ]
        then
               echo "remove old file"
               rm -f $uniq_file
        fi


echo $Date 'Starting sort unqiue file ' $uniq_file
sort -u -t\| -k3,3 -k5,5 -k7,7 $origin_filename > $uniq_file

origin_filename=`echo ${origin_filename} | awk -F '/' '{print $NF}'`
uniq_file=`echo ${origin_filename}|sed "s/\.dat/_uniq.dat/g"`
new_param=`echo ${input_param}|sed "s/\${origin_filename}/\${uniq_file}/g"`

echo $Date 'H010_Load ' $new_param
H010_Load $new_param



ret=$?



if [ $ret != 0 ]
then
	echo "Load error ,"
rm -f $uniq_file
	exit $ret
else
	echo " "  #done .truncate table successfully
fi


rm -f $uniq_file
exit 0
